<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="节日祝福" name="first">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
          <el-form-item label="主题" prop="roleName">
            <el-date-picker
              v-model="queryParams.roleName"
              type="year"
              placeholder="选择年">
            </el-date-picker>
          </el-form-item> 
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain size="mini">批量复制</el-button>
            <el-button
              type="primary"
              plain
              size="mini"
              @click="handleAdd"
            >新增</el-button>
            <el-button type="primary" plain size="mini">复制</el-button>
            <el-button type="primary" plain size="mini">编辑</el-button>
            <el-button type="primary" plain size="mini">删除</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange" >
          <el-table-column label="序号" type="index" :index="indexMethod" width="80" />
          <el-table-column label="节假日" prop="roleSort" />
          <el-table-column label="banner图" prop="roleSort">
            <template slot-scope="scope">
              <el-image
                style="width: 100px; height: 100px"
                :src="scope" />
            </template>
          </el-table-column>
          <el-table-column label="接收日期" prop="roleName" :show-overflow-tooltip="true" />
          <el-table-column label="推送时间" prop="roleKey" :show-overflow-tooltip="true"  />
          <el-table-column label="模版" prop="roleSort" :show-overflow-tooltip="true" />
          <el-table-column label="范围" prop="roleSort" />
          <el-table-column label="人群" prop="roleSort"  />
          <el-table-column label="通知渠道" prop="roleSort" />
        </el-table>


      </el-tab-pane>
      <el-tab-pane label="生日祝福" name="second">
        <el-form ref="birthForm" :model="birthForm" :rules="birthRules" label-width="80px">
          <el-form-item label="模版内容" prop="desc">
            <el-input type="textarea" v-model="birthForm.desc"></el-input>
            <ImageUpload style="margin-top: 20px;" v-model="birthForm.file" />
          </el-form-item>
          <el-form-item label="通知渠道" prop="name">
            <el-checkbox-group v-model="birthForm.name">
              <el-checkbox label="0">全选</el-checkbox>
              <el-checkbox label="1">app</el-checkbox>
              <el-checkbox label="2">站内信</el-checkbox>
              <el-checkbox label="3">短信</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">确定</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
        <div style="padding-left: 80px;">
          <div style="margin-bottom: 10px;">本月生日：张三(2024-03-04)、张三(2024-03-04)、张三(2024-03-04)</div>
          <div>下月生日：张三(2024-04-04)、张三(2024-04-04)、张三(2024-04-04)</div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <pagination
        v-show="total>0&&activeName==='first'"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    <!-- 添加或修改节日祝福 -->
    <el-dialog class="scrollbar" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="festivalForm" :model="festivalForm" :rules="festivalRules" label-width="100px">
        <el-form-item label="节假日" prop="q">
          <el-input v-model="festivalForm.q" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="接收日期" prop="w">
          <el-date-picker type="date" placeholder="选择日期" v-model="festivalForm.date1" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="推送时间" required>
          <el-form-item prop="date2">
            <el-time-picker placeholder="选择时间" v-model="festivalForm.date2" style="width: 100%;"></el-time-picker>
          </el-form-item>
        </el-form-item>
        <el-form-item label="范围" prop="desc">
          <el-radio-group v-model="festivalForm.radio">
            <el-radio :label="3">全园区</el-radio>
            <el-radio :label="6">本部及子机构</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="人群" prop="desc">
          <el-radio-group v-model="festivalForm.radio">
            <el-radio :label="3">不限制</el-radio>
            <el-radio :label="6">男</el-radio>
            <el-radio :label="6">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="模版内容" prop="desc">
          <el-input type="textarea" v-model="festivalForm.desc"></el-input>
        </el-form-item>
        <el-form-item prop="file">
          <ImageUpload style="margin-top: 20px;" v-model="festivalForm.file" />
        </el-form-item>
        <el-form-item label="通知渠道" prop="name">
            <el-checkbox-group v-model="festivalForm.name">
              <el-checkbox label="0">全选</el-checkbox>
              <el-checkbox label="1">app</el-checkbox>
              <el-checkbox label="2">站内信</el-checkbox>
              <el-checkbox label="3">短信</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 祝福详情 -->
    <el-dialog class="scrollbar" title="祝福详情" :visible.sync="openDetail" width="600px" append-to-body>
      <el-row :gutter="20">
        <el-col :span="12">主题：五一节日祝福</el-col>
        <el-col :span="12">接收者：全体员工</el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">接收时间：05-01</el-col>
        <el-col :span="12">推送时间：08:00</el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">祝福内容：升华物流园祝全体员工五一劳动节快乐！</el-col>
      </el-row>
      <el-row :gutter="20">
        <el-image
          style="width: 100%; height: 200px"
          :src="url"
          :fit="fit"></el-image>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import { listRole, getRole, delRole } from "@/api/system/role";
export default {
  dicts: ['sys_normal_disable'],
  data() {
    return {
      ids: [], // 多选数据
      activeName: 'first',
      queryParams: {},
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      },
      // 生日祝福
      birthForm: {
        name: []
      },
      // 生日校验
      birthRules: {
        name: [{ required: true, message: '请选择', trigger: 'change' }],
        desc: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      // 节日祝福检验
      festivalRules: {
        name: [{ required: true, message: '请选择', trigger: 'change' }],
        q: [{ required: true, message: '请输入', trigger: 'blur' }],
        desc: [{ required: true, message: '请输入', trigger: 'blur' }],
        date1: [{ required: true, message: '请选择', trigger: 'change' }],
        date2: [{ required: true, message: '请选择', trigger: 'change' }],
        w: [{ required: true, message: '请选择', trigger: 'change' }],
        file: [{ required: true, message: '请选择', trigger: 'change' }]
      },
      // 是否显示弹出层
      open: false,
      // 节日祝福
      festivalForm: {
        name: []
      },
      // 详情弹窗
      openDetail: false
    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 多选函数
    handleSelectionChange() {

    },
    // 序号计算
    indexMethod(index) {
      return (this.queryParams.pageNum- 1) * this.queryParams.pageSize + index + 1;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增祝福";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.title = "修改祝福";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal.confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？').then(function() {
        return delRole(roleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 表单确定
    submitForm() {
      this.$refs["festivalForm"].validate((valid) => {
        if (valid) {
          
        }
      });
    },
    // 详情弹窗
    toDetail() {
      this.openDetail = true
    }
  }
}
</script>
<style scoped lang="scss">
.el-row {
  margin: 10px 0;
}
</style>